import { describe } from '$lib';
import { processEyes3 } from './eyes';
import { log } from './log';
import { getMemory } from './memory';
import { getPlayer } from './player';
import { getPos3 } from './pos3';
import { renderVisionAndMemory, updateMemoryAndInterestingObjects } from './render';

export let visionMemory = [];

// TODO: move somewhere
export const logVisible = (e, msg, style?) => {
  if (visionMemory.indexOf(e) !== -1) {
    log(msg, style);
  }
};

export const renderTiles = (renderStack, world, r) => {
  const pc = getPlayer(world);
  const {x, y, z} = getPos3(pc);
  const vision = processEyes3(world, pc);
  let mem = getMemory(pc).get(z);
  if (mem === undefined) {
    mem = new Map();
    getMemory(pc).set(z, mem);
  }
  const interesting = updateMemoryAndInterestingObjects(world, x, y, mem, vision);
  visionMemory = interesting.all;
  return [renderVisionAndMemory(renderStack, world, vision, r, mem, x, y), interesting];
};
